package com.project.dao.Impl;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;

/**
 * 用户持久实现类
 */
@Repository
public class UserDaoImpl extends BaseDao implements IUserDao {
    @Override
    public UserBean findByName(String name,String pwd) {
        UserBean user = null;
        setConnection();
        try {
            ps = con.prepareStatement("select * from t_user where u_name=? and u_password =? ");
            ps.setObject(1, name);
            ps.setObject(2,pwd);
            rs = ps.executeQuery();
            if (rs.next()) {
                user = new UserBean();
                user.setId(rs.getInt("pk_userId"));
                user.setName(rs.getString("u_name"));
                user.setPwd(rs.getString("u_password"));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            this.close();
        }
        return user;
    }
}
